package cz.mpelant.msoe.mealchecker.request;

import java.io.UnsupportedEncodingException;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HTTP;

public class PostRequestType extends RequestType {

	private StringEntity body;

	protected PostRequestType(String url) {
		super(url);
	}

	@Override
	public HttpUriRequest getHttpRequest() {
		request = new HttpPost(requestUrl.toString());
		if (body != null)
			((HttpPost) request).setEntity(body);
		return super.getHttpRequest();
	}

	protected void addBody(String text) {
		try {
			body = new StringEntity(text, HTTP.UTF_8);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		body.setContentType("application/json");
		addHeader("Host", "msoe.managemyid.com");
		addHeader("Content-Type", "application/x-www-form-urlencoded");
		// addHeader("User-Agent",
		// "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0");
		// addHeader("Accept",
		// "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		// addHeader("Accept-Language", "en-us,en;q=0.5");
		// addHeader("Accept-Encoding", "gzip, deflate");
		// addHeader("Connection", "keep-alive");
		// addHeader("Content-Length", "36");

	}

}
